import { encodeAES, decodeAES } from '@/utils/encryption'

const key = 'KeyByVIDA'

export function setCookie(password) {
  const cipherPwd = encodeAES(password, key)
  // console.log(cipherPwd)
  window.document.cookie = `password==${cipherPwd}`
}

export function getCookie() {
  if (document.cookie.length > 0) {
    const cipher = document.cookie
    const arr = cipher.split('==')
    if (arr[0] === 'password') {
      return decodeAES(arr[1], key)
    }
  }
}

export function clearCookie() {
  setCookie('')
}
